<%@page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>众筹项目管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <div class="layui-tab-item layui-show">
                <div class="layui-tab layui-tab-brief" lay-filter="type">
                    <ul class="layui-tab-title" id="zc_tab">
                        <li <c:if test="${isCopartner == 0}">class="layui-this"</c:if>>众筹项目</li>
                        <li <c:if test="${isCopartner == 1}">class="layui-this"</c:if>>分销项目</li>
                    </ul>
                    <div class="layui-tab-content">
                        <form class="layui-form" action="${ctx}/activity/activity/zcActivityList.do" id="myForm"
                              method="post">
                            <input type="hidden" name="pageNo" id="pageNo"/>
                            <input type="hidden" name="eventId" value="${activity.eventId}"/>
                            <div class="f-search-bar">
                                <div class="search-container">
                                    <ul class="search-form-content">
                                        <li class="form-item-inline"><label class="search-form-lable">项目标题</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="title" autocomplete="off" class="layui-input"
                                                       value="${activity.title}" placeholder="请输入查询项目标题">
                                            </div>
                                        </li>
                                        <li class="form-item-inline"><label class="search-form-lable">主题名称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="eventName" autocomplete="off" class="layui-input" value="${eventName}" placeholder="请输入众筹主题名称">
                                            </div>
                                        </li>
                                        <li class="form-item-inline"><label class="search-form-lable">合&nbsp;作&nbsp;&nbsp;商</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="memberName" autocomplete="off"
                                                       class="layui-input" value="${input.memberName}"
                                                       placeholder="请输入合作商名称">
                                            </div>
                                        </li>
                                    </ul>
                                    <ul class="search-form-content">
                                        <li class="form-item-inline">
                                            <label class="search-form-lable">项目状态</label>
                                            <div class="layui-input-inline" style="width: 165px">
                                                <select name="timeStatus">
                                                    <option value="">全部</option>
                                                    <option value="0" ${input.timeStatus == 0 ? 'selected' : ''}>进行中</option>
                                                    <option value="1" ${input.timeStatus == 1 ? 'selected' : ''}>已截止</option>
                                                </select>
                                            </div>
                                        </li>
                                        <li class="form-item-inline" style="margin-left: -55px;"><label class="search-form-lable">合作商类型</label>
                                            <div class="layui-input-inline">
                                                <select name="partnerType">
                                                    <option value="">全部</option>
                                                    <option value="0" ${activity.partnerType == 0 ? 'selected="selected"' : ''}>系统客户</option>
                                                    <option value="1" ${activity.partnerType == 1 ? 'selected="selected"' : ''}>大客户</option>
                                                    <option value="2" ${activity.partnerType == 2 ? 'selected="selected"' : ''}>地接客户</option>
                                                    <option value="3" ${activity.partnerType == 3 ? 'selected="selected"' : ''}>运营客户</option>
                                                    <option value="4" ${activity.partnerType == 4 ? 'selected="selected"' : ''}>注册客户</option>
                                                </select>
                                            </div>
                                        </li>
                                        <li class="form-item-inline" style="margin-left: -55px;"><label class="search-form-lable">分销状态</label>
                                            <div class="layui-input-inline">
                                                <select name="isDistribution">
                                                    <option value="">全部</option>
                                                    <option value="1" ${activity.isDistribution == 1 ? 'selected="selected"' : ''}>分销中</option>
                                                    <option value="0" ${activity.isDistribution == 0 ? 'selected="selected"' : ''}>不可分销</option>
                                                </select>
                                            </div>
                                        </li>
                                    </ul>
                                    <ul class="search-form-content">
                                        <li class="form-item form-item-inline"><label class="search-form-lable">截止时间</label>
                                            <div class="layui-inline">
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" type="text" name="e_start"
                                                           value="${e_start}" placeholder="开始日">
                                                </div>
                                                -
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" type="text" name="e_end" value="${e_end}"
                                                           placeholder="截止日">
                                                </div>
                                            </div>
                                            <div class="cl"></div>
                                        </li>
                                        <li class="form-item-inline"><label class="search-form-lable">项目类型</label>
                                            <div class="layui-input-inline">
                                                <select name="isMultiple">
                                                    <option value="">全部</option>
                                                    <option value="0" ${isMultiple == 0 ? 'selected' : ''}>单场</option>
                                                    <option value="1" ${isMultiple == 1 ? 'selected' : ''}>多场</option>
                                                </select>
                                            </div>
                                        </li>
                                    </ul>
                                    <ul class="search-form-content">
                                        <li class="form-item"><label class="search-form-lable">发布时间</label>
                                            <div class="check-btn-inner" id="timeType">
                                                <a id="all" href="javascript:void(0);"
                                                   onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                                <input type="hidden" name="timeType" value="${input.timeType}"/>
                                            </div>
                                            <div class="layui-inline">
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" type="text" name="createStart"
                                                           value="${input.createStart}" placeholder="开始日">
                                                </div>
                                                -
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" type="text" name="createEnd"
                                                           value="${input.createEnd}" placeholder="截止日">
                                                </div>
                                            </div>
                                        </li>
                                        <li class="form-item-inline">
                                            <div class="sub-btns">
                                                <a class="layui-btn layui-btn-danger"
                                                   href="javascript:submitFunction('#myForm')">查询</a>
                                                <a class="layui-btn layui-btn-normal"
                                                   href="javascript:resetFunction('#myForm')">重置</a>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </form>
                        <c:set var="nowDate" value="<%=new Date()%>"/>
                        <div class="c-time-list-content">
                            <ul id="view">
                                <c:if test="${page.totalCount == 0}">
                                    <div class="f16 tc mt15">还没有数据，请点击右上角的“发布众筹项目”</div>
                                </c:if>

                                <c:forEach var="activity" items="${activities}">
                                    <li>
                                        <div class="detail-content">
                                            <a href="${ctx}/activity/activity/zcActivityDetail.do?actId=${activity.id}"
                                               target="_self" class="act-logo common-img"
                                            >
                                                <img src="<c:if test="${ activity.pic!= null}">${activity.pic}?imageMogr2/auto-orient/crop/200x150</c:if>" alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                            </a>
                                            <div class="detail">
                                                <div class="act-title">
                                                    <c:choose>
                                                        <c:when test="${activity.checkStatus == 0}">
                                                            <span class="status f20 red">审核中</span>
                                                        </c:when>
                                                        <c:when test="${activity.checkStatus == 1}">
                                                            <c:if test="${activity.endTime > nowDate}">
                                                                <span class="status f20 red">进行中</span>
                                                            </c:if>
                                                            <c:if test="${activity.endTime < nowDate}">
                                                                <span class="status f18 dark">已截止</span>
                                                            </c:if>
                                                        </c:when>
                                                        <c:when test="${activity.checkStatus == 2}">
                                                            <span class="status f18 dark">已拒绝</span>
                                                        </c:when>
                                                    </c:choose>
                                                    <a title="${activity.title}"
                                                       href="${ctx}/activity/activity/zcActivityDetail.do?actId=${activity.id}"
                                                       target="_self" class="title f18 ell db">${activity.title}</a>
                                                </div>
                                                <div>
                                                    <c:if test="${activity.isMultiple == 0}">
                                                        <p class="act-price">
                                                            <span style="margin-right: 10px;">截止时间：<fmt:formatDate value="${activity.endTime}" pattern="yyyy-MM-dd HH:mm"/></span>
                                                            <span style="margin-right: 10px;">报名费用：<b class="active-red"><fmt:formatNumber value="${activity.price}" pattern="0.00"/></b>元/位</span>
                                                            <span>活动地点：${activity.place}</span>
                                                        </p>
                                                    </c:if>
                                                    <p class="act-price">
                                                        <span style="margin-right: 10px;">合作商：<b class="active-red">${activity.member}</b></span>
                                                        <span>主题名称：<b class="active-red">${activity.eventName}</b></span>
                                                    </p>
                                                    <p class="act-price">
                                                        <span class="mr10">
                                                            报名人数：<strong class="red">${activity.joinNum}</strong>&nbsp;人
                                                        </span>
                                                        <c:if test="${activity.isMultiple == 0}">
                                                            <span class="mr10">
                                                                众筹成功：<strong class="red">${activity.crowdfundedNum}</strong>&nbsp;人
                                                            </span>
                                                        </c:if>
                                                        <span class="mr10">
                                                            支持人数：<strong class="red">${activity.favorerNum}</strong>&nbsp;人
                                                        </span>
                                                        <span>
                                                            已筹金额：<strong class="red"><fmt:formatNumber value="${activity.totalMoney}" pattern="0.00"/></strong>&nbsp;元
                                                        </span>
                                                    </p>
                                                    <p class="act-price">
                                                        <span class="mr10">发布时间：<fmt:formatDate value="${activity.createDate}" pattern="yyyy-MM-dd HH:mm"/></span>
                                                        <span class="mr10">修改时间：<fmt:formatDate value="${activity.updateDate}" pattern="yyyy-MM-dd HH:mm"/></span>
                                                    </p>
                                                </div>
                                                <div class="opts-btns tb-opts" style="width:475px">
                                                    <div class="comm-opts">
                                                        <c:if test="${activity.isMultiple == 0}">
                                                            <a class="qr-btn"
                                                               href="javascript:txz.openQrDialog({
                                                               title:'扫码二维码可预览分享',
                                                               detailList:[
                                                                   {
                                                                   title:'报名二维码',
                                                                   url:'${activity.bmQrCodeUrl }'
                                                                   },
                                                                   {
                                                                   title:'联合发起二维码',
                                                                   url:'${activity.qrCodeUrl }'
                                                                   },
                                                                   {
                                                                   title:'直接付款二维码',
                                                                   url:'${activity.payBySelfQrCodeUrl}'
                                                                   }
                                                               ]
                                                               })"><i
                                                                    class="iconfont icon-qrcode btn-icon"></i> 二维码</a>
                                                        </c:if>
                                                        <c:if test="${activity.isMultiple == 1}">
                                                            <a class="qr-btn"
                                                               href="javascript:txz.openQrDialog({
                                                               title:'扫码二维码可预览分享',
                                                               detailList:[
                                                                   {
                                                                   title:'报名二维码',
                                                                   url:'${activity.bmQrCodeUrl }'
                                                                   },
                                                                   {
                                                                   title:'联合发起二维码',
                                                                   url:'${activity.qrCodeUrl }'
                                                                   }
                                                               ]
                                                               })"><i class="iconfont icon-qrcode btn-icon"></i> 二维码</a>
                                                        </c:if>
                                                        <c:if test="${activity.isMultiple == 0}">
                                                            <a href="${ctx}/activity/activity/zcCrowdfundList.do?id=${activity.id}">
                                                                <i class="iconfont icon-searchlist btn-icon"></i>
                                                                数据查看
                                                            </a>
                                                            <a target="_blank"
                                                               href="${ctx}/crowdfund/analyze/list.do?targetId=${activity.id}">
                                                                <i class="iconfont icon-news btn-icon"></i>
                                                                数据分析
                                                            </a>
                                                            <a href="${ctx}/notify/template/list.do?targetId=${activity.id}">
                                                                <i class="iconfont icon-mail btn-icon"></i>
                                                                短信推送
                                                            </a>
                                                            <a href="javascript:openDialogCooperateChannel('添加合作渠道——${activity.title}', '${ctx}/activity/zcActivity/toFormCooperateChannel.do?activityId=${activity.id}', '580px', '680px')">
                                                                <i class="iconfont icon-hezuo btn-icon"></i>
                                                                合作渠道
                                                            </a>
                                                            <c:if test="${activity.endTime > nowDate}">
                                                                <a href="${ctx}/crowdfund/target/copyView.do?id=${activity.id}"> <i class="iconfont icon-copy btn-icon"></i> 复制众筹项目</a>
                                                                <a href="javascript:txz.giftUtil.openSetGift('${activity.id}', '${activity.title}', 'ZC_ACTIVITY')">配置礼包</a>
                                                            </c:if>
                                                            <a href="${ctx}/activity/activity/zcActivityForm.do?id=${activity.id}">
                                                                <i class="iconfont icon-edit btn-icon"></i> 编辑</a>
                                                            <c:if test="${activity.joinNum>=0 && activity.endTime>=nowDate && activity.systemCustomer}">
                                                                <a href="javascript:setDistribution('${activity.id}', '${activity.disCount}');" style="color: #6f5499;">设置分销</a>
                                                            </c:if>
                                                        </c:if>
                                                        <c:if test="${activity.isMultiple == 1}">
                                                            <a href="${ctx}/activityMultiple/project/listForActivity.do?id=${activity.id}">
                                                                <i class="iconfont icon-searchlist btn-icon"></i>
                                                                数据查看
                                                            </a>
                                                            <a target="_blank" href="${ctx}/activityMultiple/project/analyzeList.do?targetId=${activity.id}">
                                                                <i class="iconfont icon-news btn-icon"></i>
                                                                数据分析
                                                            </a>
                                                            <c:if test="${activity.endTime > nowDate}">
                                                                <a href="${ctx}/activityMultiple/zcActivity/copyView.do?id=${activity.id}">
                                                                    <i class="iconfont icon-copy btn-icon"></i> 复制</a>
                                                            </c:if>
                                                            <a href="${ctx}/activityMultiple/zcActivity/publishZcAct.do?id=${activity.id}">
                                                                <i class="iconfont icon-edit btn-icon"></i>
                                                                编辑
                                                            </a>
                                                        </c:if>
                                                        <a href="javascript:txz.deleteObject('确定要删除众筹项目吗？', '${ctx}/activity/activity/deleteLogic.do?id=${activity.id}')">
                                                            <i class="iconfont icon-delete btn-icon"></i> 删除
                                                        </a>
                                                        <a href="javascript:revise('${activity.id}')">校正</a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                </c:forEach>
                            </ul>
                            <div id="page_content" class="page-container"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>

    <%--设置可分销弹窗--%>
    <div id="distributionDiv" style="padding: 0px 10px">
        <div class="layui-form" lay-filter="distribution">
            <form id="distributionForm" class="layui-form mt20" method="post" action="${ctx}/activity/activity/setDistribution.do">
                <input type="hidden" name="activityId" value=""/>

                <div class="layui-form-item" style="padding-left: 17%;">
                    <div class="layui-inline">
                        <label class="layui-form-label">分销状态</label>
                        <div class="layui-input-inline" style="width: 250px" >
                            <input type="radio" name="isDistribution" value="1"
                                   title="可分销" lay-filter="isDistribution" />
                            <input type="radio" name="isDistribution" value="0"
                                   title="不可分销" lay-filter="isDistribution" />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="padding-left: 10%;">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 115px;">招募可提佣金</label>
                        <div class="layui-input-inline">
                            <input type="number" name="directBrokerage" autocomplete="off" class="layui-input" min="0">
                        </div>
                        <label class="layui-form-mid">每人</label>
                    </div>
                </div>

                <div class="layui-form-item" style="padding-left: 17%;">
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline" style="width: 200px;">
                            每招募1个众筹成功人员可获得的佣金
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="padding-left: 10%;">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 115px;">下级招募可提佣金</label>
                        <div class="layui-input-inline">
                            <input type="number" name="indirectBrokerage" autocomplete="off" class="layui-input" min="0">
                        </div>
                        <label class="layui-form-mid">每人</label>
                    </div>
                </div>
                <div class="layui-form-item" style="padding-left: 17%;">
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline" style="width: 200px;">
                            每招募一个下级合伙人，下级合伙人每招募1个众筹成功人员，该合伙人可获得的佣金
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="padding-left: 17%;">
                    <div class="layui-inline">
                        <label class="layui-form-label">提现说明</label>
                        <div class="layui-input-inline" style="width: 200px;">
                            <textarea class="layui-textarea" name="remarks"></textarea>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <%@include file="../gift/giftInclude.jsp"%>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    txz.initHeader({
        nav:[{
            name: '众筹项目管理',
            curr: true
        }],
        info:'<span class="f12">共<b>${page.totalCount}</b>条记录',
        btns:[{
            name: '发布众筹项目',
            icon: 'add',
            href: '${ctx}/activity/activity/zcActivityForm.do'
        }]
    });
    <%--showActive('${input.createStart}', '${input.createEnd}', '#timeType');--%>

    var form = null;
    var checkIndex = 0;
    $(function () {
        //加载分页
        loadPageNew({elem: 'page_content', totalCount: '${page.totalCount}', limit: '${page.limit}', page: '${page.page}'});

        layui.use(['laytpl', 'laypage', 'element', 'laydate','form'], function () {
            var laytpl = layui.laytpl, laypage = layui.laypage, laydate = layui.laydate,
                element = layui.element;

            form = layui.form;


            // 查询开始日期
            var start = {
                elem: 'input[name=e_start]'
            };

            var end = {
                elem: 'input[name=e_end]'
            };
            laydate.render(start);
            laydate.render(end);

            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);

            element.on('tab(type)', function (data) {
                var eventId = '';
                var val = $('input[name=eventId]').val();
                if (val) {
                    eventId = '?eventId=' + val;
                }
                if (data.index == 0) {
                    location.href = "${ctx}/activity/activity/zcActivityList.do" + eventId;
                }
                else if (data.index == 1) {
                    location.href = "${ctx}/activity/zcActivity/listForDistribution.do";
                }
            });

            form.on('radio(isDistribution)', function(data){
                var value = $(this).val();
                if (value == 0)
                    $('#distributionForm .layui-form-item:gt(0)').hide();
                else if (value == 1)
                    $('#distributionForm .layui-form-item:gt(0)').show();
                layer.style(checkIndex, {
                    width: '550px',
                    height: value == 0 ? '200px' : '550px',
                    top: value == 0 ? '40%' : '25%'
                });
            });
        });
    });

    // 审核
    function verify(content, checkStatus, actId) {
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            layer.close(index);
            $.post("${ctx}/activity/activity/verify.do", {
                checkStatus: checkStatus,
                actId: actId
            }, function (data) {
                if (data.success == true) {
                    util.layerAlertSuccess("审核成功", function () {
                        window.location.reload();
                    })
                }
            })
        });
    }

    function copy(id) {
        var confirmIndex = layer.confirm('确认复制众筹项目所有内容吗?',{title:'系统提示'},function(index){
            layer.close(confirmIndex);
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.post("${ctx}/crowdfund/target/copy.do", {
                id: id
            }, function (data) {
                top.layer.close(loadIndex);
                if (data.success == true) {
                    util.layerAlertSuccess("复制成功", function () {
                        window.location.reload();
                    })
                } else {
                    util.layerAlertError(data.description)
                }
            });
        });
    }

    function createCircle(actId) {
        var content = "确定要生成吗？请选择生成<br/><label for='all1' class='mr10'><input type='radio' id='all1' name='type' value='2' checked='checked' >全部报名人员</label>" +
            "<label for='success'><input type='radio' id='success' name='type' value='1' >已成功报名人员</label>";
// 		content = "确定要生成吗？";
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var type = $("[name=type]:checked").val() || '2';
            layer.close(index);
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post("${ctx}/activity/activity/createCircle.do", {
                actId: actId,
                type: type
            }, function (data) {
                layer.close(loadIndex);
                setTimeout(function () {
                    if (data.success == true) {
                        util.layerMsgSuccess("生成成功")
                    } else {
                        util.layerMsgError("生成失败")
                    }
                });
            })
        });
    }

    function send(id) {
        var content = "请选择类型<br/><label for='all1' class='mr10'><input type='radio' id='all1' name='type' value='0' checked='checked' >所有众筹</label>" +
            "<label for='success' class='mr10'><input type='radio' id='success' name='type' value='1' >众筹成功</label>" +
            "<label for='success'><input type='radio' id='success' name='type' value='2' >众筹中</label>";
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var type = $("[name=type]:checked").val() || '0';
            layer.close(index);
            $.post("${ctx}/crowdfund/event/createCircle.do", {
                id: id,
                type: type
            }, function (data) {
                if (data.success == true) {
                    util.layerMsgSuccess("生成成功")
                } else {
                    util.layerMsgError("生成失败")
                }
            })
        });
    }

    /**
     * 合作渠道弹窗
     * @param activityId 活动id
     */
    function openDialogCooperateChannel(title, url, width, height, target) {
        layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug

                    setTimeout(function () {
                        window.location.reload();
                    }, 200);
                }

            },
            cancel: function (index) {
            }
        });
    }


    /**
     * 设置当前活动的分销属性
     * @param actId
     */
    function setDistribution(actId, disCount) {
        if (actId == '' || actId == undefined) {
            layer.msg('活动参数传入有误', {
                icon: 2,
                title: '系统提示',
                time: 2000
            });
        } else {//展开属性弹窗
            $.post("${ctx}/activity/activity/getDistribution.do", {activityId: actId},
                function (resp) {
                    var disValue = undefined;
                    if (resp.success) {
                        var data = resp.data;
                        disValue = data.isDistribution;
                        $("#distributionDiv").find('[name=isDistribution]').removeAttr('checked');
                        $("#distributionDiv").find('[name=isDistribution][value=' + disValue + ']').prop('checked', true);
                        if (data.directBrokerage > 0) {
                            $("#distributionDiv").find('[name=directBrokerage]').val(data.directBrokerage);
                        }
                        if (data.indirectBrokerage > 0) {
                            $("#distributionDiv").find('[name=indirectBrokerage]').val(data.indirectBrokerage);
                        }
                        $("#distributionDiv").find('[name=remarks]').val(data.remarks);
                        if(disValue == 0) {
                            $('#distributionForm .layui-form-item:gt(0)').hide();
                        } else if (disValue == 1) {
                            $('#distributionForm .layui-form-item:gt(0)').show();
                        }

                        if (disCount > 0) {
                            $("#distributionDiv").find('[name=isDistribution][value="0"]').attr('disabled', 'disabled');
                        } else {
                            $("#distributionDiv").find('[name=isDistribution][value="0"]').removeAttr('disabled');
                        }
                        form.render();
                    } else {
                        $("#distributionDiv").find('[name=isDistribution]').removeAttr('checked');
                        $("#distributionDiv").find('[name=directBrokerage]').val('');
                        $("#distributionDiv").find('[name=indirectBrokerage]').val('');
                        $("#distributionDiv").find('[name=remarks]').val('');
                    }
                    $("#distributionDiv #distributionForm [name=activityId]").val(actId);
                    checkIndex = layer.open({
                        type: 1,
                        area: ['550px', disValue == 1 || disValue == undefined ? '560px' : '200px'],
                        title: '设置当前活动的分销属性',
                        content: $("#distributionDiv"),
                        resize: false,
                        btn: ['确定','取消'],
                        yes: function () { // 确定按钮
                            var isDistribution = $(':checked[name=isDistribution]').val();
                            var directBrokerage = $('[name=directBrokerage]').val();
                            var indirectBrokerage = $('[name=indirectBrokerage]').val();
                            if (isDistribution == undefined || isDistribution == '') {
                                util.layerMsgWarn('请选择分销状态');
                                return;
                            }
                            if (isDistribution == 1) {
                                if (directBrokerage == '') {
                                    util.layerMsgWarn('请设置招募可提佣金');
                                    return;
                                } else if (indirectBrokerage == '') {
                                    util.layerMsgWarn('请设置下级招募可提佣金');
                                    return;
                                } else if (parseFloat(directBrokerage) <= 0 || parseFloat(indirectBrokerage) <= 0) {
                                    util.layerMsgWarn('佣金不能设置为0元和负数');
                                    return;
                                }
                            }
                            if (parseFloat(directBrokerage) <= parseFloat(indirectBrokerage)) {
                                util.layerMsgWarn('下级佣金设置不合理');
                                return;
                            }
                            $.post($("#distributionDiv #distributionForm").attr('action'),
                                $("#distributionDiv #distributionForm").serialize(), function (res) {
                                    if (res.success) {
                                        util.layerMsgSuccess('当前活动分销属性设置成功', function () {
                                            window.location.reload();
                                        });
                                    } else {
                                        util.layerMsgError(res.description);
                                    }
                                });
                        },
                        btn2:function () {//取消按钮
                            layer.close(checkIndex);
                        }
                    });
                }, false);
        }
    }

    function revise(id) {
        $.post("${ctx}/activity/zcActivity/reviseTarget.do", {
            id: id
        }, function (data) {
            if (data.success) {
                util.layerAlertSuccess("校正成功", function () {
                    window.location.reload();
                })
            } else {
                util.layerAlertError("校正失败")
            }
        });
    }
</script>
</body>
</html>